package com.wzs.example.consumer;

import com.wzs.example.common.model.User;
import com.wzs.example.common.service.UserService;
import com.wzs.rpc.RpcApplication;
import com.wzs.rpc.config.RegistryConfig;
import com.wzs.rpc.config.RpcConfig;
import com.wzs.rpc.proxy.ServiceProxyFactory;
import com.wzs.rpc.registry.Registry;
import com.wzs.rpc.registry.RegistryFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class EasyConsumerExample {
    public static void main(String[] args) {
        //1.加载RpcConfig
        RpcConfig rpcConfig = RpcApplication.getRpcConfig();
        log.info("rpcConfig: {}", rpcConfig);
        //2.连接配置中心
        RegistryConfig registryConfig = rpcConfig.getRegistryConfig();
        Registry registry = RegistryFactory.getInstance(registryConfig.getRegistry());
        registry.init(registryConfig);

        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("wzs");
        User newUser = userService.getUser(user);
        if(newUser!=null) {
            System.out.println(newUser.getName());
        } else {
            System.out.println("newUser = null");
        }
//        //测试mock
//        System.out.println(userService.getUserCount());
    }
}
